# 多线程
import threading
import time


def dance():
    print('dance start!')
    time.sleep(1)
    print('dance end!')


def sing():
    print('sing start!')
    time.sleep(1)
    print('sing end!')


if __name__ == '__main__':
    t1 = threading.Thread(target=dance)
    t2 = threading.Thread(target=sing)
    t1.start()
    t2.start()
    t2.join()  # 阻塞主线程，子线程结束后主线程才会执行!
    print('king end !')


# 线程同步：每次只有一个线程来操作 锁

def func():
    global a
    a = 0
    lock.acquire()
    for var in range(10000000):
        a += 3
        print(a)
    lock.release()


def work():
    global a
    lock.acquire()
    for var in range(10000000):
        a += 1
        print(a)
    lock.release()


if __name__ == '__main__':
    lock = threading.Lock()
    t1 = threading.Thread(target=func)
    t2 = threading.Thread(target=work)
    t1.start()
    t2.start()







